package com.lianniu.mgr.productAssess.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.productAssess.dao.IAssessDetailDao;
import com.lianniu.mgr.productAssess.model.AssessDetailVo;
import com.lianniu.mgr.productAssess.service.IAssessDetailService;
import com.lianniu.mgr.util.StringUtil;
@Service
public class AssessDetailServiceImpl implements IAssessDetailService{

	private final static Logger logger = Logger.getLogger(AssessDetailServiceImpl.class);
	
	@Resource
	IAssessDetailDao assessDetailDao;
		
	@Override
	public BaseResult selectByAssessDetailForPage(AssessDetailVo curAssessDetailVo, PaginationInfo paginationInfo) {
		logger.info("selectByAssessDetailForPage begin.");
	    if (!StringUtil.isEmpty(curAssessDetailVo.getAssessContent())) {
	    	curAssessDetailVo.setAssessContent(curAssessDetailVo.getAssessContent().replace(" ", ""));
	    }
	    logger.info("selectByAssessDetailForPage SupplyProductId:" +curAssessDetailVo.getAssessContent());
	    if (!StringUtil.isEmpty(curAssessDetailVo.getId())) {
	    	curAssessDetailVo.setId(curAssessDetailVo.getId().replace(" ", ""));
	    }
	    logger.info("selectByAssessDetailForPage Id:" +curAssessDetailVo.getId());
	    if (!StringUtil.isEmpty(curAssessDetailVo.getAssLevel())) {
	    	curAssessDetailVo.setAssLevel(curAssessDetailVo.getAssLevel().replace(" ", ""));
	    }
	    logger.info("selectByAssessDetailForPage OrderId:" +curAssessDetailVo.getAssLevel());
	    logger.info("selectByAssessDetailForPage paginationInfo:" +JSON.toJSONString(paginationInfo));
	    
	    curAssessDetailVo.setPaginationInfo(paginationInfo);
	    List<AssessDetailVo> list=assessDetailDao.selectByAssessDetailForPage(curAssessDetailVo);
	    Map<String,Object> retmap=new HashMap<String,Object>();
	    retmap.put("total", paginationInfo.getTotalRecord());
	    retmap.put("curPage", paginationInfo.getCurPage());
	    retmap.put("rows", list);
	    logger.info("selectByAssessDetailForPage:  end");    
	    
	    return BaseResult.success(retmap); 
	}

	@Override
	public BaseResult selectById(AssessDetailVo assessDetailVo) {
		logger.info("selectById begin");
	    logger.info("selectById Id:" +assessDetailVo.getId());
	  
	    return BaseResult.success(assessDetailDao.selectById(assessDetailVo.getId()));
	}

	@Override
	public BaseResult deleteById(String id) {
		logger.info("deleteById begin");
		 logger.info("deleteById Id:" +id);
		  
		 return BaseResult.success(assessDetailDao.deleteById(id));
	}

	@Override
	public BaseResult deleteAssessDetail(String... id) {
		logger.info("deleteAssessDetail begin");
	    logger.info("deleteAssessDetail Ids:" +id.toString());
	    logger.info("deleteAssessDetail: input data check begin");
	   
	    BaseResult baseResult;
	    if (StringUtil.isEmpty(id.toString())) {
	      baseResult =  BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	      return baseResult;
	    }
	    logger.info("deleteAssessDetail: input data check end");
	    
	    return BaseResult.success(assessDetailDao.deleteAssessDetail(id));
	}

}
